<template lang="">
    <div>
        <van-field label='名称' v-model='form.name'/>
        选择课程<select v-model='form.course_id'>
            <option :value="i.id" v-for='i in courselist'>{{i.title}}</option>
        </select>
        上传视频 
        <video :src="'http://localhost:5000/'+from.vedio_url" controls="controls" width="200" height=150></video>
        <van-uploader :after-read="upload" />
        <van-button @click='add'>添加</van-button>
    </div>
</template>
<script>
export default {
    data(){
        return{
            form:{'video_url':''},
            courselist:[]
        }
    },
    methods: {
        upload(file){
            if(this.form.course_id){
                  //视频上传
                let formdata = new FormData()
                formdata.append('file',file.file)
                formdata.append('course_id',this.form.course_id)
                this.axios.post('vedioUpload',formdata).then(res=>{
                    this.form.video_url = res.data.url
                })
            }else{
                alert('请选择课程后再上传视频')
            }
        },
        add(){
            this.axios.post('jieM',this.form).then(res=>{
                this.getcourselist()
            })
        },
        //获取课程列表
        getcourselist(){
            this.axios.get('courseM').then(res=>{
                this.courselist = res.data.list
            })
        }
    },
    mounted() {
        this.getcourselist()
    },
}
</script>
<style lang="">
    
</style>